#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
int post_idx;
unordered_map<int, int> idx_map;
    
TreeNode* helper(int in_left, int in_right, vector<int>& inorder, vector<int>& postorder){
    // 如果这里没有节点构造二叉树了，就结束
    if (in_left > in_right) {
        return nullptr;
    }

    // 选择 post_idx 位置的元素作为当前子树根节点
    int root_val = postorder[post_idx];
    TreeNode* root = new TreeNode(root_val);

    // 根据 root 所在位置分成左右两棵子树
    int index = idx_map[root_val];

    // 下标减一
    post_idx--;
    // 构造右子树
    root->right = helper(index + 1, in_right, inorder, postorder);
    // 构造左子树
    root->left = helper(in_left, index - 1, inorder, postorder);
    return root;
}

TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
    // 从后序遍历的最后一个元素开始
    post_idx = (int)postorder.size() - 1;

    // 建立（元素，下标）键值对的哈希表
    int idx = 0;
    for (auto& val : inorder) {
        idx_map[val] = idx++;
    }
    return helper(0, (int)inorder.size() - 1, inorder, postorder);
}

int n;

inline void solution() {
    vector<int> inorder, postorder;
    cin >> n;
    for (int i = 0; i < n; i ++ ) {
        int v;
        cin >>v;
        postorder.push_back(v);
    }
    for (int i = 0; i < n; i ++ ) {
        int v;
        cin >>v;
        inorder.push_back(v);
    }
    
    TreeNode * tree = buildTree(inorder, postorder);
    
    queue<TreeNode *> q; 
    q.push(tree);
    
    vector<int> res;
    while (q.size()) {
        auto t = q.front();q.pop();
        res.push_back(t->val);
        if (t->left != nullptr) q.push(t->left);
        if (t->right != nullptr) q.push(t->right);
    }
    for (int i = 0; i < res.size(); i ++ ) {
        if (!i) cout << res[i];
        else cout << " " << res[i];
    }
    puts("");
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}